


var vm = new  Vue({

    el:"#box",

    data:{
        url:'https://jt98-hospital.oss-cn-shenzhen.aliyuncs.com/',
        status:false,
        address: ['罗湖区' , '福田区' , '南山区' , '宝安区', '龙岗区', '盐田区', '龙华区', '坪山区', '光明区'],
        searchType:['医院','科室','医生'],
        hospitalType:['综合医院','专科医院'],
        level:['一级甲等医院','一级乙等医院','一级丙等医院','二级甲等医院','二级乙等医院','二级丙等医院','三级特等医院','三级甲等医院','三级乙等医院','三级丙等医院'],
        onoff1:-1,
        onoff2:-1,
        onoff3:-1,
        onoff4:-1,
        hospitalList:[],
        departmentList:[],
        doctorList:[],
        searchQuery:'',
        queryType:'',
        result:0

    },

    methods:{
        getValue:function(index){
          return index+1;
        },

        //地址
        getAllforArea:function(event){
            var that = this;
            //选中的地区id
            var areaId = event.currentTarget.getAttribute('data-value');
            $("#address0").addClass('active');
            this.onoff1=-1;
            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //医院的类型Id
            var typeId = $("[class='set-query active'][data-query='typeId']").attr("data-value");
            //医院的等级Id
            var gradelId = $("[class='set-query active'][data-query='levelId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:gradelId,
                    addressId:areaId
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];
                    if(searchType==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';
                    }
                    else if(searchType==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';
                    }
                    else if(searchType==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        area:function (index) {
            var that = this;
            this.onoff1=index;
            $("#address0").removeClass('active');

            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //医院的类型Id
            var typeId = $("[class='set-query active'][data-query='typeId']").attr("data-value");
            //医院的等级Id
            var gradelId = $("[class='set-query active'][data-query='levelId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:gradelId,
                    addressId:index+1
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];

                    if(searchType==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';
                    }
                    else if(searchType==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';
                    }
                    else if(searchType==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });

        },
        getClassforArea: function(index){
            return {active : this.onoff1 === index}
        },

        //类型
        searchType1:function (index) {
            var that = this;
            this.onoff2=index+1;
            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //地址id
            var areaId = $("[class='set-query active'][data-query='areaId']").attr("data-value");
            //医院的类型Id
            var typeId = $("[class='set-query active'][data-query='typeId']").attr("data-value");
            //医院的等级Id
            var gradelId = $("[class='set-query active'][data-query='levelId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: index+1,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:gradelId,
                    addressId:areaId
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];
                    if((index+1)==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';

                    }
                    else if((index+1)==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';

                    }
                    else if((index+1)==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';

                    }

                })
                .catch(function (error) {
                    console.log(error);
                });

        },
        getClassforType: function(index){
            return {active : this.onoff2 === index}
        },


        //医院类型
        getHospitalType:function(event){
            var that = this;
            //选中的地区id
            var typeId = event.currentTarget.getAttribute('data-value');
            $("#ht").addClass('active');
            this.onoff3=-1;
            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //地址Id
            var areaId = $("[class='set-query active'][data-query='areaId']").attr("data-value");
            //医院的等级Id
            var gradelId = $("[class='set-query active'][data-query='levelId']").attr("data-value");


            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:gradelId,
                    addressId:areaId
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];
                    if(searchType==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';
                    }
                    else if(searchType==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';

                    }
                    else if(searchType==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });

        },
        hospitalType1:function (index) {
            var that = this;
            this.onoff3=index;
            $("#ht").removeClass('active');
            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //地址的Id
            var areaId = $("[class='set-query active'][data-query='areaId']").attr("data-value");
            //医院的等级Id
            var gradelId = $("[class='set-query active'][data-query='levelId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:index+1,
                    gradeId:gradelId,
                    addressId:areaId
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];
                    if(searchType==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';
                    }
                    else if(searchType==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';
                    }
                    else if(searchType==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });

        },
        getClassforHospital: function(index){
            return {active : this.onoff3 === index}
        },

        //医院等级
        getHospitalLeve:function(event){
            var that = this;
            //选中的地区id
            var levelId = event.currentTarget.getAttribute('data-value');
            $("#level").addClass('active');
            this.onoff4=-1;
            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //医院的类型Id
            var typeId = $("[class='set-query active'][data-query='typeId']").attr("data-value");
            //地址Id
            var areaId = $("[class='set-query active'][data-query='areaId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:levelId,
                    addressId:areaId
                }
            })
                .then(function (response) {
                    that.result = response.data.data.length;
                    that.hospitalList=[];
                    that.departmentList=[];
                    that.doctorList=[];
                    if(searchType==1){
                        that.hospitalList = response.data.data;
                        that.queryType='医院';
                    }
                    else if(searchType==2){
                        that.departmentList = response.data.data;
                        that.queryType='科室';
                    }
                    else if(searchType==3){
                        that.doctorList = response.data.data;
                        that.queryType='医生';
                    }

                })
                .catch(function (error) {
                    console.log(error);
                });


        },
        getLevel:function (index) {
            var that = this;
            this.onoff4=index;
            $("#level").removeClass('active');

            //搜索内容
            var searchQuery = $("#searchQuery").text();
            //搜索类型
            var searchType = $("[class='set-query active'][data-query='searchType']").attr("data-value");
            //医院的类型Id
            var typeId = $("[class='set-query active'][data-query='typeId']").attr("data-value");
            //地址Id
            var areaId = $("[class='set-query active'][data-query='areaId']").attr("data-value");

            axios.get('http://localhost:8080/hospital/api/search', {
                params: {
                    type: searchType,
                    queryName:searchQuery,
                    typeId:typeId,
                    gradeId:index+1,
                    addressId:areaId
                }
            })
            .then(function (response) {
                that.result = response.data.data.length;
                that.hospitalList=[];
                that.departmentList=[];
                that.doctorList=[];
                if(searchType==1){
                    that.hospitalList = response.data.data;
                    that.queryType='医院';
                }
                else if(searchType==2){
                    that.departmentList = response.data.data;
                    that.queryType='科室';
                }
                else if(searchType==3){
                    that.doctorList = response.data.data;
                    that.queryType='医生';
                }

            })
            .catch(function (error) {
                console.log(error);
            });


        },
        getClassforLevel: function(index){
            return {active : this.onoff4 === index}
        },
        tdepartmentsClick:function (tepartmentId,hospitalId) {
            window.open('department.html?tdepartmentsId='+tepartmentId+"&hospitalId="+hospitalId);
        },
        doctorClick:function (id) {
            window.open('doctor.html?doctorId='+id);
        },
        hospitalClick:function (id) {
            window.open('hospital.html?hospitalId='+id);
        }


    },
    created: function () {
        var that = this;
        var searchType = getQueryString('type');
        var searchQuery = getQueryString('queryName');
        that.searchQuery = searchQuery;
        that.onoff2=searchType;
        //alert(this.onoff2);
        //alert(searchType+searchQuery)
        axios.get('http://localhost:8080/hospital/api/search', {
            params: {
                type: searchType,
                queryName:searchQuery,
                typeId:0,
                gradeId:0,
                addressId:0
            }
        })
            .then(function (response) {
                that.result = response.data.data.length;
                that.hospitalList=[];
                that.departmentList=[];
                that.doctorList=[];

                if(searchType==1){
                    that.hospitalList = response.data.data;
                    that.queryType='医院';
                }
                else if(searchType==2){
                    that.departmentList = response.data.data;
                    that.queryType='科室';
                }
                else if(searchType==3){
                    that.doctorList = response.data.data;
                    that.queryType='医生';
                }

            })
            .catch(function (error) {
                console.log(error);
            });
    }

});
function getQueryString(key){
    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
    var result = window.location.search.substr(1).match(reg);
    return result?decodeURIComponent(result[2]):null;
}

var search = new Vue({
    el:"#search",
    data:{
        queryName:'',
        type:3,
        msg:"医生"
    },
    methods:{
        jum:function() {
            window.open('depaetment-page.html?type=' + this.type+'&queryName='+this.queryName);
        },
        getQueryType:function (event) {
            var that = this;
            that.type = event.currentTarget.getAttribute('data-value');
            if(that.type==1){
                that.msg = "医院";
            }
            else if(that.type==2){
                that.msg = "科室";
            }
            else if(that.type==3){
                that.msg = "医生";
            }

        }
    }

});

var getTokenVue = new Vue({
    el:"#getToken",
    data:{
        token:localStorage.getItem("token")
    }
    ,methods:{

    }
})

